<extend name="./public/frame.html"/>
<block name="content">
	<style>
		td .layui-table-cell{height: auto; ! important}
	</style>
<blockquote class="layui-elem-quote search">
    <div class="layui-inline">
            标题：
        <div class="layui-inline">
            <input type="text" class="layui-input" id="title">
        </div>
             开始时间：
        <div class="layui-inline">
          <input type="text" class="layui-input" id="start">
        </div>
            结束时间：
        <div class="layui-inline">
          <input type="text" class="layui-input" id="end">
        </div>
    </div>
    <div class="layui-inline">
       <button class="layui-btn" data-type="search" id="searchs">搜索</button>
    </div>
    <div class="layui-inline">
		<a class="layui-btn layui-btn-normal newsAdd_btn" href="javascript:;" data-url="{:url('Ad/add')}" onclick="add_t(this,'添加广告')" >添加广告</a>
	</div>

</blockquote>
<table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('Ad/index')}', page: true, limit: 10, id:'test'}" lay-filter="test">
  <thead>
	<tr>
      <th lay-data="{field:'ad_id', width:80,align:'center'}">广告ID</th>
      <th lay-data="{field:'title', width:200,align:'center'}">标题</th>
      <th lay-data="{field:'start_time', width:160, align:'center'}">开始时间</th>
	  <th lay-data="{field:'end_time', width:160,align:'center'}">结束时间</th>
      <th lay-data="{field:'order_type', width:100,align:'center'}">活动类型</th>
	  <th lay-data="{field:'region_name', width:100,align:'center'}">广告城市</th>
	  <th lay-data="{field:'img_url', toolbar: '#img_url',width:120,align:'center'}">广告图片</th>
	  <th lay-data="{field:'content_url', width:300,align:'center'}">链接网址</th>
      <th lay-data="{field:'loginInfo', width:100,align:'center',templet:'#logintTpl'}">登录状态</th>
	  <th lay-data="{fixed:'right', toolbar: '#barDemo', width:150, align:'center'}">操作</th>
	</tr>
  </thead>
</table>
    <script type="text/html" id="logintTpl">
        {{#if(d.is_login == 1) { }}
        <span style="color: green">需要登录</span>
        {{# } else { }}
        无需登录
        {{#}}}
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit" style="width: 50px">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" style="width: 50px">删除</a>
    </script>
    <script type="text/html" id="img_url">
        <img src="{{d.img_url}}" alt=""  style="width: 120px ! important;height: 100px ! important">
    </script>
<script>

layui.use(['form','table','laydate'], function(){
    var table = layui.table,form = layui.form,laydate = layui.laydate;
  	$('#searchs').on('click', function(){
	  var start     = $("#start").val();
	  var end       = $("#end").val();
      var title     = $("#title").val();
	  table.reload('test', {
		  url: '/admin/Ad/index', where: {
			  "start_time":start,
			  "end_time":end,
              "title":title
		  }
	  });
	});
    table.on('tool(test)', function (obj) {
        var data = obj.data;
        var ad_id = data.ad_id;
        if (obj.event === 'edit') {
            layer.open({
                type: 2,
                title: '编辑活动',
                shadeClose: true,
                shade: 0.8,
                area: ['100%', '100%'],
                content: '{:url("/admin/Ad/edit","ad_id=")}' + ad_id //iframe的url
            });
        }else if (obj.event === 'del') {
            layer.confirm('确定删除吗?',function(index){
                var url = '{:url("/admin/Ad/del","ad_id=")}' + ad_id
                $.get(url,function(data){
                    if(data.status == 1){
                        layer.msg(data.msg,{'icon':1});
                        window.location.reload();
                    }else{
                        layer.msg(data.msg,{'icon':2});
                    }
                },'json')
                layer.close(index);
            })
        }
    });
    laydate.render({
        elem: '#start' //指定元素
        ,type: 'datetime'
    });
    laydate.render({
        elem: '#end' //指定元素
        ,type: 'datetime'
    });
});
</script>
</block>
